package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


import bo.Tarea;


public class JDBCTareaDAO implements ITareaDAO {

	@Override
	public String selectTareaOID(Connection conn, String ID) {
		
		PreparedStatement stmt = null;
        ResultSet result = null;
        String oidp = null;
        String sql = "SELECT * FROM Tarea WHERE (id = ?) ";

        try {
            stmt = conn.prepareStatement(sql);
            stmt.setString(1, ID);
            result = stmt.executeQuery();

            result.next();
            oidp = result.getString("OID");
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (result != null) {
                    result.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
        return oidp;
	}

	@Override
	public Tarea selectTarea(Connection conn, String OID) {
		PreparedStatement stmt = null;
        ResultSet result = null;
        Tarea t = null;
        String sql = "SELECT * FROM Tarea WHERE (OID = ?) ";

        try {
            stmt = conn.prepareStatement(sql);
            stmt.setString(1, OID);
            result = stmt.executeQuery();

            result.next();
            t = new Tarea();
            t.setConcepto(result.getString("concepto"));
            t.setUnidades(result.getInt("unidades"));
            t.setPrioridad(result.getInt("prioridad"));
            t.setUsuario(result.getString("usuario"));
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (result != null) {
                    result.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
        return t;
	}

	@Override
	public void updatePrioridad(Connection conn, String ID, Integer p) {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateTarea(Connection conn, Tarea tarea) {
		// TODO Auto-generated method stub

	}

}
